/**
 * @author rxliuli
 */
const sysRoleApi = new class SysRoleApi extends BaseApi {
    constructor() {
        super('/api/sysRole')
    }

    async listForAll() {
        return (await rxajax.get(this.using('/list-for-all'))).data.data
    }

    listOfMap = (() => {
        const cacheFunc = rx.CacheUtil.once(() => this.listForAll())
        let fn = async () => rx.arrayToMap(await cacheFunc(), 'id', 'name')
        fn.origin = () => this.listForAll()
        fn.clear = cacheFunc.clear
        return fn
    })()

    async updateUserRole(addSysUserRoleList, deleteSysUserRoleList) {
        return (await rxajax.post(this.using('/update-user-role'), {
            addSysUserRoleList,
            deleteSysUserRoleList,
        }, {type: 'json'})).data
    }

    async updateSysMenu(addSysRoleMenuList, deleteSysRoleMenuList) {
        return (await rxajax.post(this.using('/update-sys-menu'), {
            addSysRoleMenuList, deleteSysRoleMenuList,
        }, {type: 'json'})).data
    }

    async getByUserId(userId) {
        return (await rxajax.get(this.using('/get/user-id/' + userId))).data.data
    }
}()
